Skip to content

refactor: extract magic numbers to named constants for better readability#46

Open
konard wants to merge 3 commits intolak7:mainfrom
konard:issue-42-5086281c7831
Open

refactor: extract magic numbers to named constants for better readability#46
konard wants to merge 3 commits intolak7:mainfrom
konard:issue-42-5086281c7831

Conversation

@konard
Copy link
Contributor

@konard konard commented Feb 2, 2026

Summary

  • Creates src/constants/index.ts with centralized, well-documented named constants replacing hardcoded magic numbers across the codebase
  • Adds JSDoc comments and numeric separators to Limits.ts for improved documentation
  • Replaces magic numbers in all files mentioned in issue Extract magic numbers to named constants for better readability #42 plus related files

Changes

New file: src/constants/index.ts

Centralized constants organized into categories:

  • Polling: POLLING_MAX_ATTEMPTS, POLLING_INITIAL_PHASE_DURATION_MS, POLLING_INITIAL_INTERVAL_MS, POLLING_FINAL_INTERVAL_MS
  • Debounce/Timeout: POSITION_SAVE_DEBOUNCE_MS, FEEDBACK_SUCCESS_CLOSE_DELAY_MS, COPY_FEEDBACK_RESET_DELAY_MS, SCROLL_DEBOUNCE_DELAY_MS
  • SWR/Fetching: SWR_DEDUPING_INTERVAL_MS, SWR_REFRESH_INTERVAL_MS, SWR_ERROR_RETRY_COUNT, SWR_ERROR_RETRY_INTERVAL_MS
  • UI Layout: TEXTAREA_MAX_HEIGHT_PX, PANEL_MIN/MAX_WIDTH_PERCENT, MOBILE_BREAKPOINT_PX, tree indentation constants
  • Chat/Content: CHAT_TITLE_PREVIEW_LENGTH, CHAT_TITLE_FROM_MESSAGE_LENGTH, MAX_PROMPTS_PER_CHAT
  • Database: LATEST_ARCHITECTURES_FETCH_LIMIT, DB_TRANSACTION_MAX_WAIT_MS, DB_TRANSACTION_TIMEOUT_MS
  • LLM Context Window: DEFAULT_MAX_INPUT/OUTPUT_TOKENS, WEB_SEARCH_MAX_INPUT/OUTPUT_TOKENS, MIN_REMAINING_TOKENS_THRESHOLD, FALLBACK_TRUNCATION_LENGTH, TOKEN_TRUNCATION_SAFETY_MARGIN

Updated files

File Magic numbers replaced
src/app/project/[projectId]/page.tsx Polling intervals, debounce delays, panel constraints, mobile breakpoint, tree indentation, textarea height, chat title length, prompt limit
src/app/project/page.tsx SWR config values, feedback dialog timeout
actions/project.ts Architecture fetch limit, chat title truncation length
actions/chat.ts Chat title truncation length
actions/projectDocs.ts LLM token limits, safety margin, truncation thresholds
src/lib/db.ts Transaction timeout values
Limits.ts Added JSDoc documentation, numeric separators for readability

Test plan

  • Verify the project page loads correctly and architecture polling works as expected
  • Verify SWR data fetching on the projects list page still functions properly
  • Verify chat title truncation works correctly with the named constants
  • Verify component position save debounce still works during drag operations
  • Verify panel resizing constraints are applied correctly

Fixes #42

🤖 Generated with Claude Code

Adding CLAUDE.md with task information for AI processing.
This file will be removed when the task is complete.

Issue: lak7#42
@vercel
Copy link

vercel bot commented Feb 2, 2026

@konard is attempting to deploy a commit to the lak7's projects Team on Vercel.

A member of the Team first needs to authorize it.

…lity

- Create src/constants/index.ts with centralized named constants for
  polling intervals, debounce delays, SWR config, UI layout values,
  chat truncation limits, LLM context window params, and DB timeouts
- Update src/app/project/[projectId]/page.tsx to use polling, debounce,
  UI layout, and chat constants instead of inline magic numbers
- Update src/app/project/page.tsx to use SWR and feedback constants
- Update actions/chat.ts to use CHAT_TITLE_FROM_MESSAGE_LENGTH
- Update actions/project.ts to use LATEST_ARCHITECTURES_FETCH_LIMIT
  and CHAT_TITLE_PREVIEW_LENGTH
- Update actions/projectDocs.ts to use LLM context window constants
- Update src/lib/db.ts to use DB transaction timeout constants
- Add JSDoc documentation to all constants in Limits.ts and use
  numeric separators for large numbers

Fixes lak7#42

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@konard konard changed the title [WIP] Extract magic numbers to named constants for better readability refactor: extract magic numbers to named constants for better readability Feb 2, 2026
@konard konard marked this pull request as ready for review February 2, 2026 20:08
@konard
Copy link
Contributor Author

konard commented Feb 2, 2026

🤖 Solution Draft Log

This log file contains the complete execution trace of the AI solution draft process.

💰 Cost estimation:

  • Public pricing estimate: $5.311445 USD
  • Calculated by Anthropic: $3.852684 USD
  • Difference: $-1.458760 (-27.46%)
    📎 Log file uploaded as Gist (2332KB)
    🔗 View complete solution draft log

Now working session is ended, feel free to review and add any feedback on the solution draft.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Extract magic numbers to named constants for better readability

1 participant

Comments